import { http } from "@/utils/http";

type ResultTable = {
  total?: number;
  data?: Array<any>;
};

//查询
export const getMaintainList = (data?: Record<string, any>) => {
  return http.request<ResultTable>("post", `/digitaltwins/api/v1/maintenanceWorkOrder/queryList`, {
    data
  });
};

// 删除
export const delMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceWorkOrder/delMaintenanceWorkOrder`, {
    data
  });
};

// 新增
export const addMaintainList = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/digitaltwins/api/v1/maintenanceWorkOrder/saveMaintenanceWorkOrder`, {
    data
  });
};

// 编辑
export const editMaintainList = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/digitaltwins/api/v1/maintenanceWorkOrder/updateMaintenanceWorkOrder`, {
    data
  });
};

// 新增草稿
export const addMaintainDraft = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/digitaltwins/api/v1/maintenanceWorkOrder/saveDraftMaintenanceWorkOrder`, {
    data
  });
};

// 编辑草稿
export const editMaintainDraft = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/digitaltwins/api/v1/maintenanceWorkOrder/updateDraftMaintenanceWorkOrder`, {
    data
  });
};
// 详情
export const detailMaintainList = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/digitaltwins/api/v1/maintenanceWorkOrder/getMaintenanceWorkOrder`, {
    data
  });
};

// 新增维修sop
export const addMaintainFileList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceSop/saveMaintenanceSop`, {
    data
  });
};

// 查看维修sop
export const viewMaintainFileList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceSop/queryMaintenanceSop`, {
    data
  });
};

// 审批
export const auditMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/workOrderApprovalRecord/saveApprovalRecord`, {
    data
  });
};

// 验收
export const checkMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/workOrderApprovalRecord/saveCheckRecord`, {
    data
  });
};

// 取消任务
export const cancelMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceWorkOrder/cancelWorkOrderStatus`, {
    data
  });
};

// 撤回任务
export const backMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceWorkOrder/revocationWorkOrderStatus`, {
    data
  });
};

// 领取维修任务
export const collectMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceInfo/executeMaintenanceWork`, {
    data
  });
};

/*** 维修记录 */
// 维修记录列表
export const getMaintainRecordList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceRecord/queryMaintenanceRecord`, {
    data
  });
};
// 编辑维修记录
export const editMaintainRecordList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceRecord/updateMaintenanceRecord`, {
    data
  });
};
// 删除维修记录
export const delMaintainRecordList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceRecord/deleteMaintenanceRecord`, {
    data
  });
};
// 新增维修记录
export const addMaintainRecordList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceRecord/createMaintenanceRecord`, {
    data
  });
};

// 维修记录-保存进度
export const saveMaintenanceInfo = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceInfo/saveMaintenanceInfo`, {
    data
  });
};

// 维修记录-查询维修结果
export const queryMaintenanceInfo = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/digitaltwins/api/v1/maintenanceInfo/queryMaintenanceInfo`, {
    data
  });
};

// 故障类型树
export const queryFaultTypeTree = () => {
  return http.request("post", `/digitaltwins/api/v1/faultType/queryFaultTypeTree`);
};

// 工单状态列表
export const getWorkOrderStatusList = () => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceWorkOrder/getWorkOrderStatusList`);
};

// 工单编码
export const getWorkOrderCode = () => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceWorkOrder/getWorkOrderCode`);
};

// 工单上传图片moduleName
export const getModuleName = () => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceWorkOrder/getFileModelName`);
};

// 完成维修
export const finishMaintain = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceInfo/finishMaintenance`, {
    data
  });
};

// 完成维修
export const finishFileMaintain = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/maintenanceInfo/finishMaintenanceMaterials`, {
    data
  });
};

// 运维组列表
export const getOpsGroupList = (data?: Record<string, any>) => {
  return http.request("post", `/digitaltwins/api/v1/opsGroup/queryList`, {
    data
  });
};

// 运维组成员
export const getOpsGroupMember = id => {
  return http.request<any[]>("post", `/digitaltwins/api/v1/opsGroup/queryOperateList/${id}`);
};

// 设备维修-查询备件/工具列表
export const querySparePartsAndTool = (data?: object) => {
  return http.request<Record<string, any>>("post", "/digitaltwins/api/v1/workOrderRelatedItem/getWorkOrderRelatedItem", {
    data
  });
};
// 设备维修-保存备件/工具
export const saveSparePartsAndTool = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/workOrderRelatedItem/saveWorkOrderRelatedItem", {
    data
  });
};
// 设备维修-查询维修资料列表
export const queryMaintainMeans = (data?: object) => {
  return http.request<Record<string, any>>("post", "/digitaltwins/api/v1/maintenanceInfo/queryMaintenanceMaterials", {
    data
  });
};
// 设备维修-保存维修资料
export const saveMaintainMeans = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/maintenanceInfo/saveMaintenanceMaterials", {
    data
  });
};
// 设备维修-维修进度
export const queryDealProcess = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/workOrderProgress/queryWorkOrderProgress", {
    data
  });
};
// 设备维修-选择备件出库
export const querySparePartsOutbound = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/inventoryOut/queryChooseListPage", {
    data
  });
};
// 设备维修-选择工具借用
export const queryToolBorrow = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/toolBorrowRevert/queryChooseListPage", {
    data
  });
};

/* 设备维修-故障类型 */
// 获取故障类型列表
export const queryFaultTypeList = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/faultType/queryFaultTypeList", {
    data
  });
};
// 新增故障类型
export const saveFaultType = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/faultType/saveFaultType", {
    data
  });
};
// 更新故障类型
export const updateFaultType = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/faultType/updateFaultType", {
    data
  });
};
// 删除故障类型
export const deleteFaultType = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/faultType/delFaultTypeByIds", {
    data
  });
};
// 故障类型编码
export const getFaultTypeCode = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/faultType/getFaultTypeCode", {
    data
  });
};
// 获取一级故障类型
export const getFirstFaultType = (data?: object) => {
  return http.request<any[]>("post", "/digitaltwins/api/v1/faultType/getFirstFaultType", {
    data
  });
};
